package datastructure.stack;

import java.util.Deque;
import java.util.LinkedList;

/**
 * @author XY
 * @version 1.0
 * @date 2022/2/23 9:15
 * @Description
 */
public class Leet232 {

    static class MyQueue {

        Deque<Integer> stack1;
        Deque<Integer> stack2;

        public MyQueue() {
            stack1= new LinkedList<>();
            stack2= new LinkedList<>();
        }

        public void push(int x) {
            stack1.push(x);
        }

        public int pop() {
            while(!stack1.isEmpty()){
                stack2.push(stack1.pop());
            }
            Integer pop = stack2.pop();
            while(!stack2.isEmpty()){
                stack1.push(stack2.pop());
            }
            return pop;
        }

        public int peek() {
            while(!stack1.isEmpty()){
                stack2.push(stack1.pop());
            }
            Integer pop = stack2.peek();
            while(!stack2.isEmpty()){
                stack1.push(stack2.pop());
            }
            return pop;
        }

        public boolean empty() {
            return stack1.isEmpty();
        }
    }

    public static void main(String[] args) {
        MyQueue myQueue = new MyQueue();
        myQueue.push(1); // queue is: [1]
        myQueue.push(2); // queue is: [1, 2] (leftmost is front of the queue)
        System.out.println(myQueue.peek());
        System.out.println(myQueue.pop());
        System.out.println(myQueue.empty());
    }
}
